package com.ruiboyun.liveapp.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.ruiboyun.liveapp.R;
import com.ruiboyun.liveapp.util.sys.ScreenInfo;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 落雁沙 on 2017/1/16.
 * Update by  on
 * 公司:杭州无尽信息科技有限公司
 * 邮箱：apple9302@126.com
 * Description:
 */

public class BaseDialog extends Dialog {
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.content)
    TextView content;
    @Bind(R.id.confirm)
    TextView confirm;
    @Bind(R.id.cancle)
    TextView cancle;
    @Bind(R.id.title_layout)
    LinearLayout titleLayout;
    private OnConfirmListener onConfirmListener;

    public void setOnConfirmListener(OnConfirmListener onConfirmListener) {
        this.onConfirmListener = onConfirmListener;
    }

    public interface OnConfirmListener{
        void onConfirm();
        void onCancle();
    }
    public BaseDialog(Context context) {
        super(context, R.style.shape_dialog);
        View inflate = LayoutInflater.from(context).inflate(R.layout.dialog_base, null);
        ButterKnife.bind(this,inflate);
        setContentView(inflate);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        int width=(int) (ScreenInfo.getWidth(getContext()) * 0.7);
        params.width = width;
        params.height =  WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }
    public BaseDialog setTitle(String msg){
        if (TextUtils.isEmpty(msg)){
            titleLayout.setVisibility(View.GONE);
        }else {
            title.setText(msg);
        }

        return this;
    }
    public BaseDialog setCancleText(String msg){
        cancle.setText(msg);
        return this;
    }
    public BaseDialog setConfirmText(String msg){
        confirm.setText(msg);
        return this;
    }
    public BaseDialog setContent(String msg){
        content.setText(msg);
        return this;
    }

    @OnClick({R.id.confirm, R.id.cancle})
    public void onClick(View view) {
        dismiss();
        switch (view.getId()) {
            case R.id.confirm:
                if (onConfirmListener!=null){
                    onConfirmListener.onConfirm();
                }
                break;
            case R.id.cancle:
                if (onConfirmListener!=null){
                    onConfirmListener.onCancle();
                }
                break;
        }
    }
}
